trigger  UpdateSalesTeam on Opportunity(after insert,after update)
{
    ID AASRecordTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'Advanced Ad Solutions');
    Map<Id,OpportunityTeamMember> mapoppteam=new Map<Id,OpportunityTeamMember>();
    List<OpportunityTeamMember> lstoppTeam=[Select TeamMemberRole,OpportunityId,OpportunityAccessLevel From OpportunityTeamMember where OpportunityId in:trigger.new];
    for(OpportunityTeamMember oppteam:lstoppTeam)
    {
        mapoppteam.put(oppteam.OpportunityId,oppteam);
    }
    for(Opportunity opp:trigger.new)
    {
        if(opp.RecordTypeId==AASRecordTypeID && mapOppTeam.get(opp.Id)!=null)
        {
            OpportunityTeamMember OppTeam=mapOppTeam.get(opp.Id);
            if(OppTeam.TeamMemberRole=='Seller')
            {
            OppTeam.UserId=opp.OwnerId;
            }
            else if(OppTeam.TeamMemberRole=='Sales Planner')
            {
            OppTeam.UserId=opp.Account_Manager__c;
            }
            lstoppTeam.add(OppTeam);
        }
    }
    
    update lstoppTeam;
}